/**
 * 
 */
package com.yst.metho.web.application.team.actions;

import java.util.Collection;

import nextapp.echo2.app.Button;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.event.ActionEvent;
import nextapp.echo2.app.event.ActionListener;

import com.yst.metho.web.application.SuiviProdApp;
import com.yst.metho.web.application.components.GenericEditWindow;
import com.yst.metho.web.application.team.TeamRoleListModel;
import com.yst.metho.web.application.team.TeamRolePane;
import com.yst.metho.web.application.utils.ExceptionMgt;
import com.yst.metho.web.application.utils.Locator;
import com.yst.suivi.data.team.TeamDto;
import com.yst.suivi.data.team.TeamRoleDto;

/**
 * @author yannick
 * 
 */
public class AddRole extends Button implements ActionListener
{
	private TeamDto mTeamDto;

	private TeamRoleListModel mModel;

	public AddRole(TeamDto teamDto, TeamRoleListModel model)
	{
		super("Add");
		addActionListener(this);
		setWidth(new Extent(30, Extent.PX));
		mTeamDto = teamDto;
		mModel = model;
	}

	public void actionPerformed(ActionEvent arg0)
	{
		try
		{
			Collection col = Locator.getRightsView().findProfils();
			final TeamRolePane view = new TeamRolePane(col);
			Button btn = new Button("Ok");
			btn.addActionListener(new ActionListener()
			{

				public void actionPerformed(ActionEvent arg0)
				{
					TeamRoleDto roleDto = new TeamRoleDto();
					roleDto.setNom(view.getNom());
					roleDto.setProfilId(view.getProfilId());
					roleDto.setProfilNom(view.getProfil());
					mTeamDto.add(roleDto);
					mModel.fireTableDataChanged();
				}
			});
			GenericEditWindow window = new GenericEditWindow(view, "Ajout d'un role", btn);
			window.setHeight(new Extent(300, Extent.PX));
			SuiviProdApp.getApp().getDefaultWindow().getContent().add(window);
		}
		catch (Throwable e)
		{
			ExceptionMgt.manage(e);
		}
	}
}
